#include <fstream>
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char **argv) {
  ifstream in("1.txt");
  string line;
  vector<string> vec1;
  while (getline(in, line)) {
    vec1.push_back(line);
  }

  for (size_t i = 0; i < vec1.size(); ++i) {
    cout << vec1[i] << endl;
  } //输出文本，做检验
  map<string, set<int>> map1;

  string s;
  cout << "请输入查找的单词(输入q退出)：";
  while ((cin >> s) && (s != "q")) {
    for (size_t i = 0; i < vec1.size(); ++i) {
      istringstream word(vec1[i]);
      string m;
      while (word >> m) {
        if (s == m) {
          map1[s].insert(i);
          break;
        }
      }
    }

    cout << s << " occours " << map1[s].size() << " times " << endl;
    auto it1 = map1[s].begin();
    for (; it1 != map1[s].end(); ++it1) {
      cout << "		"
           << "(line " << *it1 << ") " << vec1[*it1] << endl;
    }
  }

  return 0;
}